﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Rehabilitation.Models;

namespace Rehabilitation.Controllers
{
    public class TestDetailController : Controller
    {
        private DBEntities db = new DBEntities();


        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            if (!Request.IsAuthenticated || Session["User"] == null)
            {
                Response.Redirect("/Account/LogOff");
            }
        }

        //
        // GET: /TestDetail/

        public ActionResult Index()
        {
            return View(db.TestDetails.ToList());
        }

        //
        // GET: /TestDetail/Details/5

        public ActionResult Details(long id = 0)
        {
            TestDetail testdetail = db.TestDetails.Single(t => t.TestDetailID == id);
            if (testdetail == null)
            {
                return HttpNotFound();
            }
            return View(testdetail);
        }

        //
        // GET: /TestDetail/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /TestDetail/Create

        [HttpPost]
        public ActionResult Create(TestDetail testdetail)
        {
            if (ModelState.IsValid)
            {
                db.TestDetails.AddObject(testdetail);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(testdetail);
        }

        //
        // GET: /TestDetail/Edit/5

        public ActionResult Edit(long id = 0)
        {
            TestDetail testdetail = db.TestDetails.Single(t => t.TestDetailID == id);
            if (testdetail == null)
            {
                return HttpNotFound();
            }
            return View(testdetail);
        }

        //
        // POST: /TestDetail/Edit/5

        [HttpPost]
        public ActionResult Edit(TestDetail testdetail)
        {
            if (ModelState.IsValid)
            {
                db.TestDetails.Attach(testdetail);
                db.ObjectStateManager.ChangeObjectState(testdetail, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(testdetail);
        }

        //
        // GET: /TestDetail/Delete/5

        public ActionResult Delete(long id = 0)
        {
            TestDetail testdetail = db.TestDetails.Single(t => t.TestDetailID == id);
            if (testdetail == null)
            {
                return HttpNotFound();
            }
            return View(testdetail);
        }

        //
        // POST: /TestDetail/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            TestDetail testdetail = db.TestDetails.Single(t => t.TestDetailID == id);
            db.TestDetails.DeleteObject(testdetail);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}